package com.derbysoft.lowcostadapter.commons.model;

import com.derbysoft.lowcostadapter.commons.redis.service.RedisSerializable;
import com.derbysoft.lowcostadapter.commons.redis.utils.KeyValueHelper;
import com.derbysoft.lowcostadapter.commons.redis.utils.RedisValueBuilder;

public class RoomOccupancy implements RedisSerializable {

    public static final String PREFIX = "MAX_OCC";

    private String propertyID;

    private int propertyRoomTypeID;

    private String start;

    private String end;

    private  int minOccupancy;

    private  int maxOccupancy;

    private int minAdults;

    private int maxAdults;

    private int maxAdultsWithChildren;

    private int maxChildren;


    public String getPropertyID() {
        return propertyID;
    }

    public void setPropertyID(String propertyID) {
        this.propertyID = propertyID;
    }

    public int getPropertyRoomTypeID() {
        return propertyRoomTypeID;
    }

    public void setPropertyRoomTypeID(int propertyRoomTypeID) {
        this.propertyRoomTypeID = propertyRoomTypeID;
    }

    public String getStart() {
        return start;
    }

    public void setStart(String start) {
        this.start = start;
    }

    public String getEnd() {
        return end;
    }

    public void setEnd(String end) {
        this.end = end;
    }

    public int getMinOccupancy() {
        return minOccupancy;
    }

    public void setMinOccupancy(int minOccupancy) {
        this.minOccupancy = minOccupancy;
    }

    public int getMaxOccupancy() {
        return maxOccupancy;
    }

    public void setMaxOccupancy(int maxOccupancy) {
        this.maxOccupancy = maxOccupancy;
    }

    public int getMinAdults() {
        return minAdults;
    }

    public void setMinAdults(int minAdults) {
        this.minAdults = minAdults;
    }

    public int getMaxAdults() {
        return maxAdults;
    }

    public void setMaxAdults(int maxAdults) {
        this.maxAdults = maxAdults;
    }

    public int getMaxAdultsWithChildren() {
        return maxAdultsWithChildren;
    }

    public void setMaxAdultsWithChildren(int maxAdultsWithChildren) {
        this.maxAdultsWithChildren = maxAdultsWithChildren;
    }

    public int getMaxChildren() {
        return maxChildren;
    }

    public void setMaxChildren(int maxChildren) {
        this.maxChildren = maxChildren;
    }

    @Override
    public String toKey() {
        return PREFIX + KeyValueHelper.SEPARATOR + getPropertyID();
    }

    @Override
    public String toFiled() {
        return getStart() + KeyValueHelper.SEPARATOR + getEnd() + KeyValueHelper.SEPARATOR + Integer.toString(getPropertyRoomTypeID());
    }

    @Override
    public Long expireTime() {
        return null;
    }

    @Override
    public String value() {
        RedisValueBuilder redisValueBuilder = new RedisValueBuilder();
        redisValueBuilder.append(getMinAdults());
        redisValueBuilder.append(getMaxAdults());
        redisValueBuilder.append(getMinOccupancy());
        redisValueBuilder.append(getMaxOccupancy());
        redisValueBuilder.append(getMaxChildren());
        redisValueBuilder.append(getMaxAdultsWithChildren());
        return redisValueBuilder.toString();
    }

    public static RedisSerializable of(String key, String field, String value) {
        RoomOccupancy roomOccupancy = new RoomOccupancy();
        roomOccupancy.setPropertyID(key.split(KeyValueHelper.SEPARATOR)[1]);

        roomOccupancy.setStart(field.split(KeyValueHelper.SEPARATOR)[0]);
        roomOccupancy.setEnd(field.split(KeyValueHelper.SEPARATOR)[1]);
        roomOccupancy.setPropertyRoomTypeID(Integer.parseInt(field.split(KeyValueHelper.SEPARATOR)[2]));

        roomOccupancy.setMinAdults(Integer.parseInt(value.split(KeyValueHelper.SEPARATOR)[0]));
        roomOccupancy.setMaxAdults(Integer.parseInt(value.split(KeyValueHelper.SEPARATOR)[1]));
        roomOccupancy.setMinOccupancy(Integer.parseInt(value.split(KeyValueHelper.SEPARATOR)[2]));
        roomOccupancy.setMaxOccupancy(Integer.parseInt(value.split(KeyValueHelper.SEPARATOR)[3]));
        roomOccupancy.setMaxChildren(Integer.parseInt(value.split(KeyValueHelper.SEPARATOR)[4]));
        roomOccupancy.setMaxAdultsWithChildren(Integer.parseInt(value.split(KeyValueHelper.SEPARATOR)[5]));
        return roomOccupancy;
    }
}

